<?php

$files = $_POST['files'];
// var_dump($files);die();
$info=array();
foreach ($files as $key => $value) {
    $type = $value['fileType'];
    $base64 = $value['base64'];
    switch($type){
        case 'image/png':
            $ext='.png';
            break;
        case 'image/jpeg':
            $ext='.jpg';
            break;
        case 'image/bmp':
            $ext='.bmp';
            break;
        default:
            $ext='.jpg';
    }
    $file_path='./Uploads/'.date('Ymd').'/'.time().$key.$ext;
    if(!file_exists(dirname($file_path))){
        mkdir(dirname($file_path),0777,true);
    }
    $img_content = '';
    $img_content = str_replace('data:'.$type.';base64,','',$base64);
    $img_content = base64_decode($img_content);
    $result =file_put_contents($file_path,$img_content);
    array_push($info, $file_path);
}

echo json_encode($info);

?>